import 'dart:convert';

import 'package:largefriends/entity/json/json_parse_utils.dart';

class TypeConfigListEntity {
  TypeConfigListEntity({
    required this.isBinary,
    this.data,
  });

  factory TypeConfigListEntity.fromJson(Map<dynamic, dynamic> jsonRes) {
    return TypeConfigListEntity(
      isBinary: jsonRes.asBool('isBinary'),
      data: jsonRes.asList('data', (json) => TypeConfigEntity.fromJson(json)),
    );
  }

  bool isBinary;
  List<TypeConfigEntity>? data;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'isBinary': isBinary,
        'data': data,
      };
}

//{
//         "id": "19",
//         "label": "Hip-hop",
//         "pLabel": "Sports",
//         "pid": "1"
//       },
class TypeConfigEntity {
  TypeConfigEntity(
      {required this.key,
      required this.value,
      this.needGold = false,
      this.pLabel = "",
      this.pid = ""});

  factory TypeConfigEntity.fromJson(Map<dynamic, dynamic> jsonRes) =>
      TypeConfigEntity(
        key: jsonRes.asInts(['id', 'key'], 0),
        value: jsonRes.asStrings(['label', 'value'], ''),
        needGold: jsonRes.asBool('needGold'),
        pLabel: jsonRes.asString('pLabel'),
        pid: jsonRes.asString('pid'),
      );

  int key;
  String value;
  bool needGold;
  String pLabel;
  String pid;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'id': key,
        'label': value,
        'needGold': needGold,
        'pLabel': pLabel,
        'pid': pid,
      };
}
